<!DOCTYPE html>
<html class="x-admin-sm">
<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
	<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
	<!--[if lt IE 9]>
	<script src="./js/html5.min.js"></script>
	<script src="./js/respond.min.js"></script>
	<![endif]--></head>

<body>
<div class="layui-fluid" id="content">
	<div class="layui-row">
		<form class="layui-form">
			<div class="layui-form-item">
				<label for="review" class="layui-form-label">
					<span class="x-red">*</span>赛区</label>
				<div class="layui-input-inline" id="app">
					<select name="division" id="review">
									<option v-for="zone in zoneList" :value="zone.id">{{zone.zoneName}}</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label"><span class="x-red">*</span>公司名称</label>
				<div class="layui-input-block">
					<input maxlength="50" type="text" id="companyName" name="companyName" placeholder="请输入公司名称" lay-verify="required|companyNane" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label"><span class="x-red">*</span>联系人</label>
				<div class="layui-input-block">
					<input type="text" maxlength="10" id="contacts" name="contacts" placeholder="请输入联系人名称" lay-verify="required|userName" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label"><span class="x-red">*</span>电话</label>
				<div class="layui-input-block">
					<input type="text" id="phone" name="phone" placeholder="请输入联系电话" lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item layui-form-text">
				<label class="layui-form-label"><span class="x-red">*</span>邮箱</label>
				<div class="layui-input-block">
					<input type="text" id="email" name="email" placeholder="请输入邮箱" lay-verify="email" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="review" class="layui-form-label"></label>
				<button class="layui-btn" lay-filter="add" lay-submit="">确定</button>
			</div>
		</form>
	</div>
</div>
<script src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/abkj/match/api/undertakeunit.js"></script>
<script type="text/javascript" src="./js/abkj/match/api/zone.js"></script>
<script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
<script type="text/javascript" src="./js/abkj/slAjax.js"></script>
<script src="./js/vue.js"></script>
<script>
	var funTool=fun_tool()
	var varId=funTool.getUrlParam("id");
	var app=new Vue({
		el: '#app',
		data: {
			zoneList:[]
		},
		mounted: function() {
			var vm = this
			vm.loadZoneList()
			layui.use('form', function () {
				vm.form = layui.form;
			});
		},
		methods:{
			loadZoneList:function(){
				var vm = this
				var funTool = fun_tool();
				vm.zoneList=funTool.getAdminZoneIds();
				if(varId != null){
					vm.loadUndertakeunit();
				}
				// ZonequeryList({},function(data){
				// 	vm.zoneList=data
				// 	if(varId != null){
				// 		vm.loadUndertakeunit();
				// 	}
				// },function(status,message){
				// 	// alert(message);
				// })
			},
			getZoneName:function(varId){
				for(var i=0;i<this.zoneList.length; ++i){
					if(this.zoneList[i].id==varId){
						return this.zoneList[i].zoneName
					}
				}
				return null;
			},
			loadUndertakeunit:function(){
				UndertakeUnitgetObj(varId,function(data){
					//编辑功能，获取当前编辑项信息
					// alert(JSON.stringify(data))
					// var zoneName=app.getZoneName(data.zoneId);
					var zoneId=data.zoneId

					setTimeout(function(){
						var review=document.getElementById("review")
						for (i=0;i<review.options.length;i++){
							  if (review.options[i].value==zoneId){
									review.options[i].selected=true
									// alert(review.options[i])
									break
								}
						}
						form.render('select')
					},1000)
					// var findStr="option:contains('"+zoneName+"')"
                  document.getElementById("companyName").value=data.companyName
                    // $("#companyName").val();//String 承办公司名称
                    $("#phone").val(data.phone);//String 联系电话
                    $("#email").val(data.email);//String 邮箱地址
                    $("#contacts").val(data.contacts)//String 联系人
				})
			}

		}
	})
</script>
<script>
var form
layui.use(['form', 'layer'],
	function () {
		$ = layui.jquery
	form = layui.form,
			layer = layui.layer

		//自定义验证规则
		form.verify({
			companyNane: function (value) {
				const reg = new RegExp("[\\u4E00-\\u9FFF]+", "g")
				if (!reg.test(value)) {
					return '请输入0-50个汉字的公司名称'
				}
			},
			userName: function (value) {
				const reg = new RegExp("[\\u4E00-\\u9FFF]+", "g")
				if (!reg.test(value)) {
					return '请输入1-10个汉字的名称'
				}
			},
			pass: [/(.+){6,12}$/, '密码必须6到12位'],
			repass: function (value) {
				if ($('#L_pass').val() != $('#L_repass').val()) {
					return '两次密码不一致'
				}
			}
		})

		//监听提交
		form.on('submit(add)',
			function (data) {
				var objAdd={
					zoneId:$("#review").val(),//Integer 赛区ID
                    zoneName:$("#review").find("option:selected").text(),//String 赛区名称
                    companyName:$("#companyName").val(),//String 承办公司名称
                    phone:$("#phone").val(),//String 联系电话
                    email:$("#email").val(),//String 邮箱地址
                    contacts:$("#contacts").val()//String 联系人
				}
				if(varId == null){
					UndertakeUnitaddObj(objAdd,function(data){
					console.log(data)
					//发异步，把数据提交给php
					layer.alert("增加成功", {
							icon: 6
						},
						function () {
							// 获得frame索引
							var index = parent.layer.getFrameIndex(window.name)
							//关闭当前frame
							parent.layer.close(index)

							// 可以对父窗口进行刷新
							xadmin.father_reload()
						})
					},function(status,message){

					})
				}else{
					objAdd.id=varId
					UndertakeUnitupdateById(objAdd,function(data){
						// 更新成功
						console.log(data)
						//发异步，把数据提交给php
						layer.alert("修改成功", {
								icon: 6
							},
							function () {
								// 获得frame索引
								var index = parent.layer.getFrameIndex(window.name)
								//关闭当前frame
								parent.layer.close(index)

								// 可以对父窗口进行刷新
								xadmin.father_reload()
							})
						},function(status,message){

						})
				}


				return false
			})

	})
</script>
<script>var _hmt = _hmt || [];
(function () {
	var hm = document.createElement("script")
	hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190"
	var s = document.getElementsByTagName("script")[0]
	s.parentNode.insertBefore(hm, s)
})()</script>
</body>

</html>
